package CutLoad.components.window
{
	import CutLoad.Base;
	import CutLoad.components.CTextField;
	import CutLoad.components.Skin;
	import CutLoad.components.container.Container;
	import CutLoad.components.container.ContainerH;
	import CutLoad.components.loadbar.ILoadBar;
	
	import flash.display.MovieClip;
	import flash.text.TextFieldAutoSize;
	/**
	 * 等待窗口 
	 * @author smallerbird mail:smallerbird@gmail.com  site:www.mkigm.com QQ群:49983196
	 * 
	 */	
	public class CWait extends Base implements ILoadBar
	{
		private var window:CWindow;
		private var contendContainer:ContainerH
		private var txtContent:CTextField;
		//
		private var txtLoad:CTextField;
		
		private var clone_strContent:String;
		private var clone_strTitle:String;
		private var clone_w:Number;
		private var clone_h:Number;
		private var clone_isDrag:Boolean;
		//
		private var baseLoad:Base;
		public function init(strContent:String,strTitle:String="请等待",w:Number=200,h:Number=80,isDrag:Boolean=true):void{
			clone_strContent=strContent;
			clone_strTitle=strTitle;
			clone_w=w;
			clone_h=h;
			clone_isDrag=isDrag;
			//
			window=new CWindow();
			window.init(strTitle,false,isDrag,false,w,h,this);
			window.show(this);
			window.setWH(w,h);
			//加载动画
			var sysKinTem:Array=Skin.getInstance().getSkin(5)
			var loadIco:MovieClip=Base.getStrClassObject(sysKinTem[0]) as MovieClip
			loadIco.width=sysKinTem[1];
			loadIco.height=sysKinTem[2];
			baseLoad=Base.getBase(loadIco);
			//
			contendContainer=new ContainerH();
			contendContainer.init({w:window.getContainer().getShowWidth(),h:window.getContainer().getShowHeight(),isAuto:false,xspace:5,yspace:5});
			contendContainer.append(baseLoad);
			//
			txtContent=new CTextField();
			txtContent.init(strContent,CTextField.getTextFormat(1,0x000000,14),false);
			txtContent.getTextField().wordWrap=true;
			var widthTem:Number=window.getContainer().getShowWidth()-sysKinTem[1]-5
			txtContent.getTextField().width=widthTem;
			txtContent.getTextField().height=window.getContainer().getShowHeight();
			txtContent.getTextField().autoSize=TextFieldAutoSize.LEFT;
			txtContent.getTextField().wordWrap=true;
			var heightTem:Number=Math.abs((sysKinTem[2]-txtContent.getTxtHeight())/2)
			//contendContainer.appendXY(txtContent,sysKinTem[1]-5,heightTem+10);
			contendContainer.append(txtContent,true);
			contendContainer.setTakeWH();
			//
			window.getContainer().append(contendContainer);
			//
			txtLoad=new CTextField();
			txtLoad.init();
			txtLoad.setAutoSize(1);
			txtLoad.text="";
			contendContainer.appendXY(txtLoad,15,10+((sysKinTem[2]-txtLoad.getTxtHeight()))/2);
			//
			setTitle(strTitle)
			setContent(strContent);
		}	
		private function update():void{
			contendContainer.update();
			window.setContentWH(contendContainer.getShowWidth(),contendContainer.getShowHeight());
			//contendContainer.showGuide();
		}
		/**
		 * 显示关闭按钮并设置关闭要用到的函数. 
		 * @param funClose 格式：function(自已的引用:CWindow)  注：这里传入的关闭方法，是直接作用于CWait组件所引用的CWindows的showCloseBtnFun方法,所以“自已的引用:CWindow”,不是指向CWait，如果要关闭CWait组件,可以
		 * 直接调用CutLoad.closeWait();
		 * 
		 */		
		public function showCloseBtn(funClose:Function):void{
			this.window.setFunCloseBtn(funClose);
		}
		/**
		 * 设置标题 文字
		 * @param str
		 * 
		 */		
		public function setTitle(str:String):void{
			this.window.setTitle(str);
		}
		/**
		 * 设置内容文字 
		 * @param str
		 * 
		 */		
		public function setContent(str:String):void{
			txtContent.text=str;
			update()
		}
		/**
		 * 不停调用 
		 * 
		 */		
		public function dreawing():void
		{
		}
		/**
		 * 设置值 
		 * @param per
		 * @param strTalkYou
		 * 
		 */		
		public function setValue(per:Number, strTalkYou:String):void
		{
			txtLoad.text=String(Math.floor(per*100))+"%";
			setContent(strTalkYou);
		}
		/**
		 * 显示或隐藏 
		 * @param isShow
		 * 
		 */		
		public function showHide(isShow:Boolean):void
		{
		}
		/**
		 * 克隆 
		 * @return 
		 * 
		 */		
		public function clone():ILoadBar
		{
			var wait:CWait=new CWait();
			wait.init(this.clone_strContent,this.clone_strTitle,this.clone_w,this.clone_h,this.clone_isDrag);
			return wait;
		}
		override public function setWH(w:Number=0, h:Number=0):void{
			window.setWH(w,h);
		}
		/**
		 * 设置当加载完成后，要运行一个方法。 
		 * @param fun
		 * 
		 */		
		public function setLoadCompleteDo(fun:Function):void{
			
		}
		/**
		 * 当加载完成后，是否要运行一个方法
		 * @return 
		 * 
		 */		
		public function isLoadCompleteDo():Boolean{
			return false;
		}
		/**
		 * 加载完成时调用这个方法
		 * 
		 */				
		public function loadComplete():void{
			
		}
	}
}